/* Standard Macromedia functions for rollovers */

function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function swap_back() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swap() { //v3.0
  var i,j=0,x,a=swap.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/* ====================================================================================== */
/* jQuery document-is-ready function. Place all calls here */
jQuery(document).ready(function() {

	var hp_frame = 1

	//preloadImages('images/mb_brands_f2.png','images/mb_campaigns_f2.png','images/mb_client_area_f2.png','images/mb_client_list_f2.png','images/mb_contact_us_f2.png','images/mb_interactive_f2.png','images/mb_latest_f2.png','images/mb_literature_f2.png','images/mb_login_f2.png','images/mb_news_f2.png','images/mb_newsletter_f2.png','images/mb_opportunities_f2.png','images/mb_our_clients_f2.png','images/mb_our_experience_f2.png','images/mb_our_expertise_f2.png','images/mb_our_team_f2.png','images/mb_our_unique_points_f2.png','images/mb_testimonials_f2.png','images/mb_who_we_are_f2.png','images/mf_brands_f2.png','images/mf_campaigns_f2.png','images/mf_interactive_f2.png','images/mf_literature_f2.png');

	$("a.tip").easyTooltip();

	$(".taEmail").click(function() {
		var newhref = this.href.replace(/%20@%20/,"@");
		//alert(newhref);
		$(this).attr("href",newhref).click();
	});


	// ============================================================
	// rotate homepage images
	// There are four places for images. We intend to rotate them across the four positions,
	// but don't want any duplicates on screen so can't use a random process.
	// PLAN: have 8 images and show the first four. Then show the other four.
	// Each time randomise the positions.
	if($("#home_image1")) {
		$("#home_image1").cycle();
		$("#home_image2").cycle();
		$("#home_image3").cycle();
		$("#home_image4").cycle();
	}
	// ============================================================

	
	// ============================================================
	// Font Resize methods. Provide 3 links with classes 
	// .resetFont, .increaseFont, decreaseFont. Size is saved in a 
	// Cookie (requires jqery.cookie.js as well as jquery.js)
	// Set size of body {} font
	// ------------------------------------------------------------
	var originalFontSize = $('body').css('font-size');
	var originalFontSizeNum = parseFloat(originalFontSize);

	var cookie_name = 'textsize';
	
	if($.cookie(cookie_name))
		$('body').css('font-size', $.cookie(cookie_name));
	else
		$('body').css('font-size', originalFontSize);

	// ------------------------------------------------------------
	// Reset Cookie
	$(".resetFont").click(function() {
		$('body').css('font-size', originalFontSize);
		$.cookie(cookie_name, null);
	});
	
	// ------------------------------------------------------------
	// Increase Font Size
	$(".increaseFont").click(function(){
		var currentFontSize = $('body').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize);
		if(currentFontSizeNum < 20) {
			var newFontSize = currentFontSizeNum*1.2;
			$('body').css('font-size', newFontSize);
			$.cookie(cookie_name, newFontSize);
		}
		return false;
	});
	// ------------------------------------------------------------
	// Decrease Font Size
	$('.decreaseFont').click(function(){
		var currentFontSize = $('body').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		if(currentFontSizeNum > 8) {
			var newFontSize = currentFontSizeNum*0.8;
			$('body').css('font-size', newFontSize);
			$.cookie(cookie_name, newFontSize);
		}
		return false;
	});

	// ============================================================
	$("#signup").submit(function(e){
     				
		// stop normal link click
		e.preventDefault();

		// send request
		if(this.signup_email.value != "Email address" && this.signup_email.value != "" && this.signup_name.value != "First name" && this.signup_name.value != "") {
			$("#signup_status").empty().addClass("ajax-loading");
			
			$.post("newsletterSignup.php", {signup_email:$("#signup_email").val(),signup_name:$("#signup_name").val()}, function(result) {
				// format and output result. fadeTo(3000,1) simulates delay(), which isn't in jQuery
				$("#signup_status").html(result).show("fast").fadeTo(3000,1).hide("fast");
				$("#signup_status").removeClass("ajax-loading");
			});
		}
	});

	$("#news_nav a#up").click(function(e) {
		e.preventDefault();	// stop normal link click
		var news_height = $("#news").height();
		var news_top = parseFloat($("#news").css('top'));
		var page_height = 360;

		if(Math.abs(news_top) > 0) {
			var news_up = news_top + page_height + "px";
			$("#news").stop().animate({top:news_up},'fast');
		}
	});

	$("#news_nav a#down").click(function(e) {
		e.preventDefault();	// stop normal link click
		var news_height = $("#news").height();
		var news_top = parseFloat($("#news").css('top'));
		var page_height = 360;
//alert($("#news").is("[@animated]"));
		
		if(Math.abs(news_top) < (news_height - page_height)) {
			var news_down = parseFloat($("#news").css('top')) - page_height + "px";
			$("#news").stop().animate({top:news_down},'fast');
		}
	});
});



// *************************************************************************
function checkQT() {
	if (navigator.plugins) {
		for (i=0; i < navigator.plugins.length; i++ ) {
			if (navigator.plugins[i].name.indexOf("QuickTime") >= 0) {
				haveqt = true;
			}
		}
	}
	if ((navigator.appVersion.indexOf("Mac") > 0) && (navigator.appName.substring(0,9) == "Microsoft") && (parseInt(navigator.appVersion) < 5) ) {
		haveqt = true;
	}
}

// *************************************************************************
